#!/usr/bin/python
# Magic eight ball -- ask it a question

import bot
import sys
import random
import time

def log(*args):
	"Replacement for print, which doesn't deal with unicode well"
	msg=u" ".join(map(unicode,args))
	print msg.encode(sys.getdefaultencoding(),"replace")
	
username='bottest'
domain="gmail.com"
password='this isn''t my password'

answers=[ "Signs point to yes.", "Yes.", "Reply hazy, try again.", 
"Without a doubt.", "My sources say no.", "As I see it, yes.",
"You may rely on it.", "Concentrate and ask again.", "Outlook not so good.",
"It is decidedly so.", "Better not tell you now.", "Very doubtful.",
"Yes - definitely.", "It is certain.", "Cannot predict now.", "Most likely.",
"Ask again later.", "My reply is no.", "Outlook good.", "Don't count on it. ",
]


class EightBallBot(bot.Bot):

	def ev_msg(self,user,msg):
		log(user,":",msg)
		self.msg(user,random.choice(answers))

	def ev_unsubscribe(self,user,msg):
		# User removed us from their list
		# So remove them from ours.
		log(user,"unsubscribing:",msg)
		self.removeUser(user)
		self.rejectUser(user)

	def ev_unsubscribed(self,user,msg):
		# User has forced us to remove them from our list
		log(user,"unsubscribing:",msg)
		self.removeUser(user)
		self.rejectUser(user) # Remove us from their list

	def ev_subscribe(self,user,msg):
		# User added us to their list, so add them to ours
		log(user,"subscribing:",msg)
		self.addUser(user)
		self.acceptUser(user)

me = EightBallBot(username,password)

me.connect()
me.setOnline('Magic 8 ball, ask me a question')
	
me.run()
